package com.coupons.business.common.util;

import java.io.InputStream;
import java.util.Collection;
import java.util.Properties;

import com.coupons.business.common.exception.BaseCouponsAppException;



public class Helper 
{
	private static String SEPARATOR  = "$&&$";
	public static String getCachekey(int partnerId, int pageId, int merchantId)
	{		
		return partnerId+SEPARATOR+pageId+SEPARATOR+merchantId;
	} 
	
	public static String getCachekey(int patrnerId, int pageId, int merchantId, int offerId)
	{				
		return patrnerId+SEPARATOR+pageId+SEPARATOR+merchantId+offerId;
	} 
	
	public static String getCachekey(int partnerId, String pageName)
	{		
		return partnerId+SEPARATOR+pageName;
	}
	
	public boolean isValidCollection(Collection collection)
	{
		boolean flag=false;
		
		if(null!=collection && collection.size()>0)
			flag=true;
		
		return flag;
	}
	
	public boolean isValidString(String str)
	{
		boolean flag=false;
		
		if(null!=str && !"".equals(str))
			flag=true;
		
		return flag;
	}
	
	public static String getContentCachekey(int patrnerId, String contentId)
	{				
		return patrnerId+SEPARATOR+"content"+SEPARATOR+contentId;
	} 
	
	public static String getContentCachekey(int patrnerId, String pageName, String categoryName)
	{				
		return patrnerId+SEPARATOR+"content"+SEPARATOR+pageName+SEPARATOR+categoryName;
	} 
	
	public String getPageContent(String straContentId)throws BaseCouponsAppException
	{
		
		
		Properties objcProps;
		objcProps = new Properties(); 
		try {
		InputStream objlInputStream = (InputStream)this.getClass().getResourceAsStream("/myprops.properties");
		
		objcProps.load(objlInputStream);
		System.out.println("loaded");
		} catch (Exception e) {
			e.printStackTrace();
			throw new BaseCouponsAppException(e);
		}
		return objcProps.getProperty(straContentId);
		
	}
	public static String prepareValidkeyWord(String searchKey)
	{
		String newString = searchKey.replaceAll("'", "''");
		System.out.println("newString "+newString);
		return newString;
		
	}
	
}
